import Vue from 'vue';
import App from './App';
import router from './router';
import Components from './components';
import ddApi from './components/js/ddApi';
Vue.prototype.$ddApi = ddApi; //钉钉api
import {
  openPage,
  goBack
} from './components/js/openPage';
Vue.prototype.$openPage = openPage; //打开新的页面
Vue.prototype.$goBack = goBack; //返回上一级
import {
  alert
} from './components/dialog/index';
Vue.prototype.$alert = alert; //弹框
import store from './store';
import {
  Toast
} from 'vant';

//钉钉权限验证
import {
  authLogin,
  ddConfig
} from '@/components/auth/dingtalk.js';
import {
  getParams
} from '@/components/js/utils/decodeURIComponent.js';

Vue.config.productionTip = false;

Vue.use(Components); //使用插件

NewVue();
async function NewVue() {
  // 获取链接上的一些参数
  const getUrlParamsRes = await getParams(['corpId', 'APPkey']);
  // console.log("getUrlParamsRes", getUrlParamsRes);
  localStorage.setItem('getUrlParamsRes', JSON.stringify(getUrlParamsRes));

  // 获取钉钉环境
  store.state.isDDMobilePlatform = await ddApi.isDDMobilePlatform();


  // 免登
  // 签名 免登
  // ddConfig(),
  // ddConfigRes,
  const [authLoginRes] = await Promise.all([authLogin()]); //同步掉
  // if (!ddConfigRes.success) {
  //   Toast(ddConfigRes.errorMsg); //只做提醒
  // }
  // role_type=0是普通员工没有我的审批,=1是领导有我的审批
  sessionStorage.setItem('role_type', authLoginRes.data.role_type || 0);

  if (!authLoginRes.success) {
    Toast(authLoginRes.errorMsg);
    return;
  }




  new Vue({
    el: '#app',
    router,
    store,
    components: {
      App,
    },
    template: '<App/>',
  });
}
